//
//  SCBlockBtn.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/24.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "SCBlockBtn.h"
@interface SCBlockBtn ()

// 注意 : 给 block 变量写合成存取, 一定要用 copy
@property (nonatomic, copy) block myBlock;

@end@implementation SCBlockBtn
// 利用 block 生成 button 对象
+ (SCBlockBtn *)buttonWithFrame:(CGRect)frame type:(UIButtonType)type title:(NSString *)title titleColor:(UIColor *)titleColor borderColor:(UIColor *)color backgroundColor:(UIColor *)backgroundColor number:(NSInteger)number font:(UIFont *)font andBlock:(block)tempBlock {
    
    SCBlockBtn *button = [SCBlockBtn buttonWithType:type];
    
    button.backgroundColor = backgroundColor;
    
    //    layer 层 corner 角 radius 半径
    button.layer.cornerRadius = number;
    button.layer.masksToBounds = YES;
    
    button.layer.borderWidth = 0.5;
    button.layer.borderColor = color.CGColor;
    
    button.frame = frame;
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    button.titleLabel.font = font;
    [button addTarget:button action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    
    button.myBlock = tempBlock;
    
    return button;
    
}

- (void)buttonClicked:(SCBlockBtn *)button{
    
    NSLog(@"这里是 buttonClicked 方法的内部");
    
    //    触发按钮
    button.myBlock(button);
    
}

@end
